package com.hxalex.simulationhandle.accessbilityService.manger;

import android.content.Context;

import com.hxalex.simulationhandle.accessbilityService.command.base.BaseCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.CheckBrowserIsMainCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.ClearAllPageCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.EditSearchContentCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.OpenBrowserCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.SearchBaiduInfoCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.SearchWebContentCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.SearchWebContentCountCommand;
import com.hxalex.simulationhandle.accessbilityService.command.search.UpdateWebSiteCommand;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.CheckBrowserIsMainReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.ClearAllPageReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.EditSearchContentReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.OpenBrowserReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.SearchBaiduInfoReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.SearchWebContentCountReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.SearchWebContentReceiver;
import com.hxalex.simulationhandle.accessbilityService.receiver.search.UpdateWebSiteReceiver;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * Created by hx_Alex on 2018/5/28.
 */

public class CommandManger {
    private static  CommandManger commandManger=new CommandManger();
    private ArrayBlockingQueue<BaseCommand> commandQueue = new ArrayBlockingQueue<BaseCommand>(1024);
    private CommandManger(){};
    public static CommandManger getManger()
    {
        return commandManger;
    }


    public ArrayBlockingQueue<BaseCommand> getCommandQueue() {
        return commandQueue;
    }
    
    
    public void loadBrowserCommand(Context context,boolean isFrist)
    {

        SearchManger searchManger = SearchManger.getSearchManger(context);
        commandQueue.offer(new UpdateWebSiteCommand(searchManger,new UpdateWebSiteReceiver(searchManger)));
        commandQueue.offer(new CheckBrowserIsMainCommand(searchManger,new CheckBrowserIsMainReceiver(searchManger)));
        commandQueue.offer(new EditSearchContentCommand(searchManger,new EditSearchContentReceiver(searchManger)));
        commandQueue.offer(new SearchBaiduInfoCommand(searchManger,new SearchBaiduInfoReceiver(searchManger)));
        commandQueue.offer(new SearchWebContentCountCommand(searchManger,new SearchWebContentCountReceiver(searchManger)));
        commandQueue.offer(new SearchWebContentCommand(searchManger,new SearchWebContentReceiver(searchManger)));
    }

    public void loadBrowserCommandAgain(Context context, boolean isFrist) {
        SearchManger searchManger = SearchManger.getSearchManger(context);
      commandQueue.offer(new ClearAllPageCommand(searchManger, new ClearAllPageReceiver(searchManger)));
        commandQueue.offer(new OpenBrowserCommand(searchManger, new OpenBrowserReceiver(searchManger)));
    }
}
